require "magic_pair"
require "test/unit"

class TestMagicPair < Test::Unit::TestCase
  def test_count_of_magic_pairs_is_4_when_51
    magic_pair = MagicPair.new 51
    assert_equal(4, magic_pair.get_number_of_pairs)
  end
  
  def test_count_of_magic_pairs_is_0_when_20
    magic_pair = MagicPair.new 20
    assert_equal(0, magic_pair.get_number_of_pairs)
  end

  def test_maximum_product_and_pair_when_51
    magic_pair = MagicPair.new 51

    expected = {
      :product => 1530,
      :pair => [[30, 51].sort!]
    }
    assert_equal(expected, magic_pair.get_maximum_product_and_pair)
  end

  def test_maximum_product_and_pair_when_21
    magic_pair = MagicPair.new 21

    expected = {
      :product => 126,
      :pair => [[6, 21].sort!]
    }
    assert_equal(expected, magic_pair.get_maximum_product_and_pair)
  end

  def test_maximum_product_and_pair_when_20
    magic_pair = MagicPair.new 20

    expected = {
      :product => 0,
      :pair => []
    }
    assert_equal(expected, magic_pair.get_maximum_product_and_pair)
  end

  def test_initialization_exception_for_invalid_type_argument
    assert_raises ArgumentError do
      MagicPair.new "This is an invalid argument."
    end
  end

  def test_initialization_exception_for_invalid_range_argument
    assert_raises ArgumentError do
      MagicPair.new 1
    end
    assert_raises ArgumentError do
      MagicPair.new -51
    end
  end

  def test_no_initialization_exception_for_valid_argument
    assert_nothing_raised do
      MagicPair.new 2
    end
  end
end